var app = getApp();
var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');

Page({
    data: {
        status: 'all',
        cash_list: [],
        show_no_data_tip: false,
        is_loading: !1,
        page:1
    },
    onLoad: function(a) {
      console.log(a);
      this.LoadCashList(a.status==null?'all':a.status,1);
    },
    onReady: function() {},
    onShow: function() {},
    LoadCashList: function(a,page) {
        var t = this;
        t.setData({
            status: a,
            page : page
        }), wx.showLoading({
            title: "正在加载",
            mask: !0
        });
        util.request(api.getCashList, {
                status: t.data.status,
                page: t.data.page
        }).then(function (res) {
          wx.hideLoading();
          console.log(res);
          var y = t.data.cash_list.concat(res.data);
          t.setData({
            cash_list: y,
          })
          if (t.data.cash_list.length<=0){
            t.setData({
              show_no_data_tip: true
            })
          }
          if (5 > res.data.length ) {
            t.setData({
              is_loading: true
            })
          } else {
            t.setData({
              is_loading: false
            })
          }
        }).catch((res) => {
          console.log(res);
          wx.hideLoading();
          wx.showModal({
            title: '注意',
            content: '服务器出小差了，请稍候重试.',
            showCancel: false
          });
        })
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
      var i = this;
      if (i.data.is_loading == false) {
        var p = i.data.page + 1

        i.setData({
          page: p
        })
        this.LoadCashList(-1, p);

      }
    }
});